{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# sklearn中的多项式回归和Pipeline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.random.uniform(-3, 3, size=100)\n",
    "X = x.reshape(-1, 1)\n",
    "y = 0.5 * x**2 + x + 2 + np.random.normal(0, 1, size=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import PolynomialFeatures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "poly  = PolynomialFeatures(degree=2) # degree表示最多添加几次幂，及多项式最多是几阶的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PolynomialFeatures(degree=2, include_bias=True, interaction_only=False,\n",
       "                   order='C')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly.fit(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = poly.transform(X) # 把数据转换为多次幂特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.        , -0.9553743 ,  0.91274005],\n",
       "       [ 1.        , -0.74769459,  0.5590472 ],\n",
       "       [ 1.        ,  2.47165582,  6.1090825 ],\n",
       "       [ 1.        ,  0.88061138,  0.7754764 ],\n",
       "       [ 1.        , -2.51402981,  6.32034587]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X2[:5, :] # 第一列全为1，是X的0次方的意思"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "lin_reg2 = LinearRegression()\n",
    "lin_reg2.fit(X2, y)\n",
    "y_predict2 = lin_reg2.predict(X2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAD4CAYAAADFAawfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3deXgUVdb48e9NCCQIEpGIEFZRAQUlY1wwioIiuAHiCOK+veir47iBgDOIOirwQ2Vw5nVhRlEQBQWMCiKKICiOaFgUIaIsgxCQ1bBIgEDu74+bYBJ6qe6u6qrqPp/nyaPpdLpvNZVTt86991yltUYIIYR3pbjdACGEEKFJoBZCCI+TQC2EEB4ngVoIITxOArUQQnhcDSdetEGDBrpFixZOvLQQQiSkRYsWbdNaZwX6mSOBukWLFhQUFDjx0kIIkZCUUuuC/UxSH0II4XESqIUQwuMkUAshhMdJoBZCCI+TQC2EEB4ngVoIITxOArUQQnicBGohRMLLX1JE3og5tBw8g7wRc8hfUmTvG2gNgwdDYaG9r1vOkQUvQgjhFflLihgybRklpYcAKCouYci0ZQD0ysm2500mTICRIyE7G9q2tec1K5EetRAioY2atfJwkK5QUnqIUbNW2vMGv/wC998PeXlwzz32vGY1EqiFEAltY3FJRI9H7N57Ye9eeOUVSHEmpEqgFkIktMaZGRE9HpFp02DKFBg2DFq3jv31gpBALYRIaAO7tSYjLbXKYxlpqQzsFmNg3bED7r4bcnJgwIDYXisMGUwUQiS0igHDUbNWsrG4hMaZGQzs1jr2gcSHHoJt22DmTEhLs6GlwUmgFkI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uxJTS3AwM01q/4mqjoqSUOg/4HFiG+dsHeERr/aF7rYqeUuo04HXMeZYCvK21fiKm1/RSoBZCCHEkT6U+hBBCHEkCtRBCeJwEaiGE8DgJ1EII4XESqIUQwuMkUAshhMdJoBZCCI/7/2HLDP4eWqSHAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x, y)\n",
    "plt.plot(np.sort(x), y_predict2[np.argsort(x)], color='r') # x排序了，y_predict2是一个x对应一个y,y应该按照x的索引顺序取值，所以要取x地argsort\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 1.0045632 , 0.48325968])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg2.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.041679502807576"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lin_reg2.intercept_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 关于PolynomialFeatures"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> PolynomialFeatures当幂数上升的时候回导致X的列数快速上升"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.arange(1, 11).reshape(-1, 2) # 10个数据调整为两列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5, 2)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2],\n",
       "       [ 3,  4],\n",
       "       [ 5,  6],\n",
       "       [ 7,  8],\n",
       "       [ 9, 10]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "poly = PolynomialFeatures(degree=2)\n",
    "poly.fit(X)\n",
    "X2 = poly.transform(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  1.,   1.,   2.,   1.,   2.,   4.],\n",
       "       [  1.,   3.,   4.,   9.,  12.,  16.],\n",
       "       [  1.,   5.,   6.,  25.,  30.,  36.],\n",
       "       [  1.,   7.,   8.,  49.,  56.,  64.],\n",
       "       [  1.,   9.,  10.,  81.,  90., 100.]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X2 # PolynomialFeatures当幂数上升的时候回导致X的列数快速上升,会生成三个二次幂(X1的平方、X1*X2、X2的平方)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5, 6)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X2.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> PolynomialFeatures当幂数上升的时候回导致X的列数快速上升\n",
    "![PolynomialFeatures当幂数上升时导致X在transform后列数快速上升](images/PolynomialFeatures当幂数上升时导致X在transform后列数快速上升.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用sklearn中的Pipeline来完成多项式回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''重要'''\n",
    "x = np.random.uniform(-3, 3, size=100)\n",
    "X = x.reshape(-1, 1)\n",
    "y = 0.5 * x**2 + x + 2 + np.random.normal(0, 1, 100)\n",
    "\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "# Pipeline可以把我们的多个步骤合并到一起\n",
    "poly_reg = Pipeline([\n",
    "    (\"poly\", PolynomialFeatures(degree=2)),\n",
    "    (\"std_scaler\", StandardScaler()),\n",
    "    (\"lin_reg\", LinearRegression())\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "poly_reg.fit(X, y)\n",
    "y_predict = poly_reg.predict(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD5CAYAAAA+0W6bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3deXhV1dn38e8iJBhwiAoOBBC0iCMSiSNaq6iAWskjDmBV2lqp1qqtlgrSp2htC5Vaq75qi2OtVLBCo4gKKo4o+kCDAmIqDigBNVQGgQgZ1vvHSjDDmc8+Z+998vtcVy7IyRnWme699r3Wupex1iIiIuHTwe8GiIhIahTARURCSgFcRCSkFMBFREJKAVxEJKQUwEVEQqpjvCsYYx4AzgK+sNYe1njZHsAMoDfwMXC+tXZ9vPvq2rWr7d27dxrNFRFpfxYvXrzOWtut9eUm3jxwY8y3gc3Aw80C+C3Al9baycaYccDu1trr4zWitLTULlq0KKUnICLSXhljFltrS1tfHjeFYq19Bfiy1cXDgb81/v9vQFnaLRQRkaSkmgPf21q7F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jT3e82pcsYM8UY817j8/qXMabI7zZ5wRhznjFmuTGmwRgT6hkBxpihxphKY8xKY8w4v9vjBWPMA8aYL4wxy/xui1eMMT2NMS8aY1Y0fvau8btNmRaqAA5Msdb2t9YOAJ4Cfu13gzzwHHCYtbY/8B9gvM/t8coy4BzgFb8bkg5jTB5wFzAMOAQYZYw5xN9WeeIhYKjfjfBYHXCdtfZg4Fjgyhx5r6IKVQC31m5q9msXIPQJfGvtPGttXeOvC4EefrbHK9baFdbaXNhU82hgpbX2Q2vtdmA6MNznNqXNWvsK8KXf7fCStXattfbfjf//ClgB5HSN5NDVAzfG/A64BNgInOxzc7z2Q2CG342QFoqBT5v9vho4xqe2SIKMMb2BEuBNf1uSWYEL4MaY54F9IvxpgrX2CWvtBGCCMWY88FNgYlYbmIJ4z6nxOhNwp4DTstm2dCTyvHKAiXBZ6M/8cpkxZmdgJvCzVmftOSdwAdxae2qCV/0HMIcQBPB4z8kYMxo4CxhsQzSvM4n3KsxWAz2b/d4DWONTWyQOY0w+LnhPs9bO8rs9mRaqHLgxpm+zX88G3vOrLV4xxgwFrgfOttZu9bs90sb/AX2NMX2MMQXASOBJn9skERhjDHA/sMJa+ye/25MNoVrIY4yZCfQDGnBVDS+31lb526r0GGNWAp2A/zZetNBae7mPTfKEMeZ/gDuBbsAGYIm1doi/rUqNMeYM4M9AHvCAtfZ3PjcpbcaYR4Hv4Cr3fQ5MtNbe72uj0mSMOQF4FViKixEAN1hrn/avVZkVqgAuIiLfCFUKRUREvqEALiISUgrgIiIhpQAuIhJSCuAiIiGlAC4iElIK4CIiIaUALiISUv8f99KN59F9bd4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x, y)\n",
    "plt.plot(np.sort(x), y_predict[np.argsort(x)], color='r')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7417706598382324"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly_reg.score(X, y)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
